package com.dy.design_pattern_study.composite_pattern.dome2.impl;

import com.dy.design_pattern_study.composite_pattern.dome2.Company;

import java.util.ArrayList;
import java.util.List;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-12
 * @Content 具体公司类 -树枝节点
 */
public class ConcreteCompany extends Company {

    private List<Company> children = new ArrayList<>();

    public ConcreteCompany(String name) {
        super(name);
    }

    @Override
    public void add(Company company) {
        children.add(company);
    }

    @Override
    public void remove(Company company) {
        children.remove(company);
    }

    @Override
    public void display(int depth) {
        System.out.println(printStr(depth));
        for (Company child : children) {
            child.display(depth + 2);
        }
    }

    @Override
    public void lineOfDuty() {
        for (Company child : children) {
            child.lineOfDuty();
        }
    }
}
